<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- Bootstrap -->
    <div th:include="pages/include :: public_css"></div>
    <style type="text/css">
        #table_length,
        #table_info {
            display: inline-block;
        }

        #table_length {
            padding-top: 8px;
        }

        #table_paginate {
            display: inline-block;
        }

        #table_status {
            display: flex;
            justify-content: space-between;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div th:include="pages/include :: header"></div>
    <div class="row">
        <div class="col-md-2">
            <div th:include="pages/include :: menus"></div>
        </div>
        <div class="col-md-10">
            <div id="content">
                <div class="panel panel-info">
                    <div class="panel-heading">
                        <form th:action="@{/dorm/search}" method="post" style="display: inline-block;" class="form-inline">
                            <div class="form-group">
                                <input type="text" class="form-control input-sm" name="name" placeholder="名称">
                            </div>
<!--                            <div class="form-group">-->
<!--                                <select name="gender" class="form-control input-sm">-->
<!--                                    <option th:value="null">请选择</option>-->
<!--                                    <option value="0">女</option>-->
<!--                                    <option value="1">男</option>-->
<!--                                </select>-->
<!--                            </div>-->
                            <button type="submit" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-search"></span></button>
                        </form>
                        <div class="pull-right">
                            <a th:href="@{/dorm/toAddOrEdit}" class="btn btn-success btn-sm" id="btn_add">添加宿舍楼</a>
                            <button type="button" class="btn btn-success btn-sm">批量删除</button>
                        </div>
                    </div>
                    <div class="panel-body">
                        <table class="table table-striped table-bordered table-hover" id="mytable">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>名称</th>
                                <th>简介</th>
                                <th>管理员</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="item : ${pageInfo.list}">
                                <td th:text="${item.id}">Onions</td>
                                <td th:text="${item.name}">2.41</td>
                                <td th:text="${item.intro}">2.41</td>
                                <td th:text="${item.intro}">2.41</td>
                                <td >
                                    <a th:href="@{/dorm/toAddOrEditWithParent(parent=${item.id})}" class="btn btn-info">添加寝室</a>
                                    <a th:href="@{/dorm/toAddOrEdit(id=${item.id})}" class="btn btn-info">编辑</a>
                                    <button th:onclick="|javascript:doDelete('${item.id}')|" type="button" class="btn btn-danger">删除</button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <nav class="text-center">
                            <span>一共[[${pageInfo.total}]]条记录解决居中问题</span>
                            <ul class="pagination">
                                <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
                                <!-- 中间页 -->
                                <li th:each="pageNum:${#numbers.sequence(0, pageInfo.pages - 1)}" th:class="${pageNum + 1 == pageInfo.pageNum} ? 'active'">
                                    <a th:href="'/dorm/toList?pageNum=' + ${pageNum + 1} + '&pageSize=' + ${pageInfo.pageSize}" th:text="${pageNum + 1}"><span class="sr-only">(current)</span></a>
<!--                                    <a th:href="'/list?pageNum=' + ${pageNum}" th:text="${pageNum + 1}" th:style="'font-weight:bold;background: #6faed9;'"></a>-->
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="pages/include :: public_js"></div>
<script type="text/javascript">
    $(document).ready(function () {
      console.log("list 加载完成");
      menuActive();
    });

    function search() {

    }

    function doDelete(id) {
      console.log(id);
      let b = confirm("确认是否删除id为" + id + "的数据?");
      if (b) {
        location.href = "/dorm/delete?id=" + id;
      }
    }
</script>
</body>
</html>
